package es.fonso.codigo;

import java.io.IOException;

import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;

import es.fonso.visual.MainWindow;

public class Url {
	
	private String link;
	protected Document doc;
	
	protected final static String USER_AGENT="Mozilla/5.0 (Windows; U; Windows NT 5.1; de; rv:1.9) Gecko/2008052906 Firefox/3.0";
	protected final static String MAIN_URL = "http://divxatope.com";
	private final int TIMEOUT= 3000;
	private final int reintentos=10;
	

	public Url(String url) {
		this.link=url;
	}

	public String getLink() {
		return link;
	}

	public void setLink(String link) {
		this.link = link;
	}
	
	public void obtenerCodigo() throws Exception {
		for (int i=0;i<reintentos;i++){
			try {						
					this.doc = Jsoup.connect(this.link).userAgent(USER_AGENT).timeout(TIMEOUT).get();
					return ;						
			} catch (Exception e) {
				MainWindow.log("Error al obtener el codigo;" + e.getLocalizedMessage());
			}
		}
		throw new Exception("Error al obtener el codigo de la pagina");
	}

	public Document getDoc() {
		return doc;
	}

	public void setDoc(Document doc) {
		this.doc = doc;
	}
	
	

}
